/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.ui.rich.learn.learn_view.element_view.command;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.ListIterator;

import br.ufmg.dees.insane.model.disc.element.Element;
import br.ufmg.dees.insane.model.disc.fem.FemModel;
import br.ufmg.dees.insane.ui.rich.learn.learn_controller.Controller;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.CmdButton;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnInterface;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.dialog.MatrixViewTableDialog;
import br.ufmg.dees.insane.util.IVector;

/**
*
* @author Moreira, Renata & Pitangueira, Roque
* @since May 2005
*/
public class ElmCompleteForcesDialog {
	
	private static final long serialVersionUID = 1L;
	private LearnInterface parent;
	private FemModel fmodel;
	private MatrixViewTableDialog dlg;
	
	/**
	 * Constructor method, calling super with the especific title.
	 *
	 * @param parent The parent of the class.
	 * @see gui.Interface
	 */
	public ElmCompleteForcesDialog(LearnInterface parent) {
		this.parent = parent;
		fmodel = parent.getView().getController().getModel();
		
        //Number Format
		DecimalFormat fmt = new DecimalFormat();
        DecimalFormatSymbols fsym = new DecimalFormatSymbols();
        fsym.setDecimalSeparator('.');
        fmt.setDecimalFormatSymbols(fsym);
        fmt.applyPattern("0.000E00");
        
        ((Controller)parent.getView().getController()).getDriver().numberElementEquations();
		((Controller)parent.getView().getController()).getDriver().reduceEquationsVector();		
		dlg = new MatrixViewTableDialog("Element Global Forces Vector", ((Element)fmodel.getElementsList().get(0)).globalEquivalentForceVector().getSize());
		ArrayList sel = this.parent.getView().getController().getSelection();
		ListIterator selLI = sel.listIterator();
		while(selLI.hasNext()){
			Element elm = (Element)selLI.next();
			IVector gf = elm.globalEquivalentForceVector();
			CmdButton[][] fVector = new CmdButton[gf.getSize()][1];
			//double[][] fVector = new double[gf.getSize()][1];
			for(int i =0; i< gf.getSize(); i++)
				for(int j =0; j<1; j++)
				fVector[i][j]= new CmdButton(String.valueOf(fmt.format(gf.getElement(i))));
			
			String[] lineNames = new String[gf.getSize()];
			for(int k=0; k<gf.getSize(); k++)
				lineNames[k] = ""+elm.getReducedEquation(k);	
			
			String[] colNames = new String[1];
			for(int k=0; k<1; k++)
				colNames[k] = "Forces";	
			dlg.addOutputTable(elm.getLabel(),lineNames, colNames,fVector);
		}
    }
		
    public int showDialog(){
    	return this.dlg.showDialog();
    }


}
